home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / dflat_r_.arc / APPLICAT.C next >
Text File  |  1991-10-02  |  19KB  |  752 lines

  1. /* ------------- applicat.c ------------- */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <dos.h>
  7. #include <process.h>
  8. #include "dflat.h"
  9.  
  10. static int ScreenHeight;
  11.  
  12. #ifdef INCLUDE_DIALOG_BOXES
  13. extern DBOX Display;
  14. extern DBOX Windows;
  15. #ifdef INCLUDE_LOGGING
  16. extern DBOX Log;
  17. #endif
  18. #endif
  19.  
  20. static void ShellDOS(WINDOW);
  21. static void CreateMenu(WINDOW);
  22. static void CreateStatusBar(WINDOW);
  23. static void CloseAll(WINDOW);
  24. static void SelectColors(WINDOW);
  25. static void SetScreenHeight(int);
  26. #ifdef INCLUDE_MULTIDOCS
  27. static void ChooseWindow(WINDOW, int);
  28. static void SelectTexture(void);
  29. static void SelectBorder(WINDOW);
  30. static void SelectTitle(WINDOW);
  31. static void SelectStatusBar(WINDOW);
  32. #endif
  33. #ifdef INCLUDE_DIALOG_BOXES
  34. static void SelectLines(WINDOW);
  35. #endif
  36. static void FixTabMenu(void);
  37. static int DisplayModified;
  38.  
  39. int ApplicationProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  40. {
  41.     int rtn, WasVisible;
  42.  
  43.     switch (msg)    {
  44.         case CREATE_WINDOW:
  45.             ScreenHeight = SCREENHEIGHT;
  46.             if (!LoadConfig())
  47.                 cfg.ScreenLines = ScreenHeight;
  48.             if (cfg.InsertMode)
  49.                 SetCommandToggle(&MainMenu, ID_INSERT);
  50.             if (cfg.WordWrap)
  51.                 SetCommandToggle(&MainMenu, ID_WRAP);
  52. #ifdef INCLUDE_DIALOG_BOXES
  53.             if (!isVGA() && !DisplayModified)    {
  54.                 /* ---- modify Display Dialog Box for EGA, CGA ---- */
  55.                 CTLWINDOW *ct, *ct1;
  56.                 int i;
  57.                 ct = FindCommand(&Display, ID_OK, BUTTON);
  58.                 if (isEGA())
  59.                     ct1 = FindCommand(&Display, ID_50LINES, RADIOBUTTON);
  60.                 else    {
  61.                     CTLWINDOW *ct2;
  62.                     ct2 = FindCommand(&Display, ID_COLOR, RADIOBUTTON) - 1;
  63.                     ct2->dwnd.w++;
  64.                     for (i = 0; i < 7; i++)
  65.                         (ct2+i)->dwnd.x += 8;
  66.                     ct1 = FindCommand(&Display, ID_25LINES, RADIOBUTTON) - 1;
  67.                 }
  68.                 for (i = 0; i < 4; i++)
  69.                     *ct1++ = *ct++;
  70.                 DisplayModified = TRUE;
  71.             }
  72.             if (cfg.Border)
  73.                 SetCheckBox(&Display, ID_BORDER);
  74.             if (cfg.Title)
  75.                 SetCheckBox(&Display, ID_TITLE);
  76.             if (cfg.StatusBar)
  77.                 SetCheckBox(&Display, ID_STATUSBAR);
  78.             if (cfg.Texture)
  79.                 SetCheckBox(&Display, ID_TEXTURE);
  80.             if (cfg.mono == 1)
  81.                 PushRadioButton(&Display, ID_MONO);
  82.             else if (cfg.mono == 2)
  83.                 PushRadioButton(&Display, ID_REVERSE);
  84.             else
  85.                 PushRadioButton(&Display, ID_COLOR);
  86.             if (cfg.ScreenLines == 25)
  87.                 PushRadioButton(&Display, ID_25LINES);
  88.             else if (cfg.ScreenLines == 43)
  89.                 PushRadioButton(&Display, ID_43LINES);
  90.             else if (cfg.ScreenLines == 50)
  91.                 PushRadioButton(&Display, ID_50LINES);
  92. #endif
  93.             if (SCREENHEIGHT != cfg.ScreenLines)    {
  94.                 SetScreenHeight(cfg.ScreenLines);
  95.                 if (WindowHeight(wnd) == ScreenHeight ||
  96.                         SCREENHEIGHT-1 < GetBottom(wnd))    {
  97.                     WindowHeight(wnd) = SCREENHEIGHT-1;
  98.                     GetBottom(wnd) = GetTop(wnd)+WindowHeight(wnd)-1;
  99.                     wnd->RestoredRC = WindowRect(wnd);
  100.                 }
  101.             }
  102.             SelectColors(wnd);
  103.             FixTabMenu();
  104. #ifdef INCLUDE_MULTIDOCS
  105.             SelectBorder(wnd);
  106.             SelectTitle(wnd);
  107.             SelectStatusBar(wnd);
  108. #endif
  109.             rtn = BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  110.             if (wnd->extension != NULL)
  111.                 CreateMenu(wnd);
  112. #ifdef INCLUDE_STATUSBAR
  113.             CreateStatusBar(wnd);
  114. #endif
  115. #ifdef INCLUDE_HELP
  116.             LoadHelpFile();
  117. #endif
  118.             SendMessage(NULLWND, SHOW_MOUSE, 0, 0);
  119.             return rtn;
  120. #ifdef INCLUDE_STATUSBAR
  121.         case ADDSTATUS:
  122.             if (wnd->StatusBar != NULLWND)    {
  123.                 if (p1 && *(char *)p1)
  124.                     SendMessage(wnd->StatusBar, SETTEXT, p1, p2);
  125.                 else 
  126.                     SendMessage(wnd->StatusBar, CLEARTEXT, 0, 0);
  127.                 SendMessage(wnd->StatusBar, PAINT, 0, 0);
  128.             }
  129.             return TRUE;
  130. #endif
  131.         case SETFOCUS:
  132.             if (p1 && inFocus != wnd)    {
  133.                 /* ---- setting focus ------ */
  134.                 SendMessage(inFocus, SETFOCUS, FALSE, 0);
  135.                 /* remove window from list */
  136.                 RemoveFocusWindow(wnd);
  137.                 /* move window to end of list */
  138.                 AppendFocusWindow(wnd);
  139.                 inFocus = wnd;
  140.                 SendMessage(wnd, BORDER, 0, 0);
  141.                 return TRUE;
  142.             }
  143.             break;
  144.         case SIZE:
  145.             WasVisible = isVisible(wnd);
  146.             if (WasVisible)
  147.                 SendMessage(wnd, HIDE_WINDOW, 0, 0);
  148.             if (p1-GetLeft(wnd) < 30)
  149.                 p1 = GetLeft(wnd) + 30;
  150.             BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  151.             CreateMenu(wnd);
  152. #ifdef INCLUDE_STATUSBAR
  153.             CreateStatusBar(wnd);
  154. #endif
  155.             if (WasVisible)
  156.                 SendMessage(wnd, SHOW_WINDOW, 0, 0);
  157.             return TRUE;
  158.         case KEYBOARD:
  159. #ifdef INCLUDE_HELP
  160.             if ((int)p1 == F1)
  161.                 break;
  162. #endif
  163. #ifdef INCLUDE_SYSTEM_MENUS
  164.             if ((int)p1 == ALT_HYPHEN)    {
  165.                 BuildSystemMenu(wnd);
  166.                 return TRUE;
  167.             }
  168.             if (WindowSizing || WindowMoving)
  169.                 break;
  170. #endif
  171.         /* ----- fall through here ----- */
  172.         case SHIFT_CHANGED:
  173.             PostMessage(wnd->MenuBarWnd, msg, p1, p2);
  174.             return TRUE;
  175.         case PAINT:
  176.             if (isVisible(wnd))
  177.                 ClearWindow(wnd, (RECT *)p1, cfg.Texture ?
  178.                     APPLCHAR : ' ');
  179.             return TRUE;
  180.         case COMMAND:
  181.             switch ((int)p1)    {
  182. #ifdef INCLUDE_HELP
  183.                 case ID_HELP:
  184.                     DisplayHelp(wnd, DFlatApplication);
  185.                     break;
  186.                 case ID_HELPHELP:
  187.                     DisplayHelp(wnd, "HelpHelp");
  188.                     break;
  189.                 case ID_EXTHELP:
  190.                     DisplayHelp(wnd, "ExtHelp");
  191.                     break;
  192.                 case ID_KEYSHELP:
  193.                     DisplayHelp(wnd, "KeysHelp");
  194.                     break;
  195.                 case ID_HELPINDEX:
  196.                     DisplayHelp(wnd, "HelpIndex");
  197.                     break;
  198. #ifdef INCLUDE_RELOADHELP
  199.                 case ID_LOADHELP:
  200.                     LoadHelpFile();
  201.                     break;
  202. #endif
  203. #endif
  204. #ifdef INCLUDE_LOGGING
  205.                 case ID_LOG:
  206.                     MessageLog(wnd);
  207.                     if (CheckBoxSetting(&Log, ID_LOGGING))
  208.                         SetCommandToggle(&MainMenu, ID_LOG);
  209.                     else
  210.                         ClearCommandToggle(&MainMenu, ID_LOG);
  211.                     break;
  212. #endif
  213.                 case ID_DOS:
  214.                     ShellDOS(wnd);
  215.                     return TRUE;
  216.                 case ID_EXIT:
  217.                 case ID_SYSCLOSE:
  218.                     PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  219.                     break;
  220. #ifdef INCLUDE_DIALOG_BOXES
  221.                 case ID_DISPLAY:
  222.                     if (DialogBox(wnd, &Display, TRUE, NULL))    {
  223.                         SendMessage(wnd, HIDE_WINDOW, 0, 0);
  224.                         SelectColors(wnd);
  225.                         SelectLines(wnd);
  226. #ifdef INCLUDE_MULTIDOCS
  227.                         SelectBorder(wnd);
  228.                         SelectTitle(wnd);
  229.                         SelectStatusBar(wnd);
  230.                         SelectTexture();
  231. #endif
  232.                         CreateMenu(wnd);
  233. #ifdef INCLUDE_STATUSBAR
  234.                         CreateStatusBar(wnd);
  235. #endif
  236.                         SendMessage(wnd, SHOW_WINDOW, 0, 0);
  237.                     }
  238.                     break;
  239. #endif
  240.                 case ID_TAB2:
  241.                     cfg.Tabs = 2;
  242.                     FixTabMenu();
  243.                     break;
  244.                 case ID_TAB4:
  245.                     cfg.Tabs = 4;
  246.                     FixTabMenu();
  247.                     break;
  248.                 case ID_TAB6:
  249.                     cfg.Tabs = 6;                    
  250.                     FixTabMenu();
  251.                     break;
  252.                 case ID_TAB8:
  253.                     cfg.Tabs = 8;
  254.                     FixTabMenu();
  255.                     break;
  256.                 case ID_SAVEOPTIONS:
  257.                     SaveConfig();
  258.                     break;
  259. #ifdef INCLUDE_MULTIDOCS
  260.                 case ID_WINDOW:
  261.                     ChooseWindow(wnd, (int)p2-2);
  262.                     break;
  263.                 case ID_CLOSEALL:
  264.                     CloseAll(wnd);
  265.                     break;
  266. #endif
  267.                 case ID_SYSRESTORE:
  268.                 case ID_SYSMOVE:
  269.                 case ID_SYSSIZE:
  270.                 case ID_SYSMINIMIZE:
  271.                 case ID_SYSMAXIMIZE:
  272.                     return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  273.                 default:
  274.                     if (inFocus != wnd->MenuBarWnd && inFocus != wnd)
  275.                         PostMessage(inFocus, msg, p1, p2);
  276.                     break;
  277.             }
  278.             return TRUE;
  279. #ifdef INCLUDE_SYSTEM_MENUS
  280.         case LEFT_BUTTON:    {
  281.             WINDOW wnd1 = wnd;
  282.             int mx, my;
  283.             if (WindowSizing || WindowMoving)
  284.                 return FALSE;
  285.             if (SendMessage(wnd, INSIDE_WINDOW, p1, p2))    {
  286.                 if (inFocus && inFocus != wnd->MenuBarWnd)
  287.                     if (SendMessage(inFocus, INSIDE_WINDOW, p1, p2))
  288.                         wnd1 = inFocus;
  289.                 mx = (int) p1 - GetLeft(wnd1);
  290.                 my = (int) p2 - GetTop(wnd1);
  291.                 if (HitControlBox(wnd1, mx, my))    {
  292.                     BuildSystemMenu(wnd1);
  293.                     return TRUE;
  294.                 }
  295.             }
  296.             break;
  297.         }
  298. #endif
  299.         case CLOSE_WINDOW:    {
  300.             char exmsg[80];
  301.             sprintf(exmsg, "Exit %s?", DFlatApplication);
  302.             if (!YesNoBox(exmsg))
  303.                 return FALSE;
  304.             CloseAll(wnd);
  305.             PostMessage(NULLWND, STOP, 0, 0);
  306.             rtn = BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  307.             if (ScreenHeight != SCREENHEIGHT)
  308.                 SetScreenHeight(ScreenHeight);
  309. #ifdef INCLUDE_HELP
  310.             UnLoadHelpFile();
  311. #endif
  312.             SendMessage(NULLWND, HIDE_MOUSE, 0, 0);
  313.             return rtn;
  314.         }
  315.         default:
  316.             break;
  317.     }
  318.     return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  319. }
  320.  
  321. static void SwitchCursor(void)
  322. {
  323.     SendMessage(NULLWND, SAVE_CURSOR, 0, 0);
  324.     SwapCursorStack();
  325.     SendMessage(NULLWND, RESTORE_CURSOR, 0, 0);
  326. }
  327.  
  328. /* ------- Shell out to DOS ---------- */
  329. static void ShellDOS(WINDOW wnd)
  330. {
  331.     SendMessage(wnd, HIDE_WINDOW, 0, 0);
  332.     SwitchCursor();
  333.     if (ScreenHeight != SCREENHEIGHT)
  334.         SetScreenHeight(ScreenHeight);
  335.     SendMessage(NULLWND, HIDE_MOUSE, 0, 0);
  336.     printf("To return to %s, execute the DOS exit command.",
  337.                     DFlatApplication);
  338.     spawnl(P_WAIT, getenv("COMSPEC"), NULL);
  339.     if (SCREENHEIGHT != cfg.ScreenLines)
  340.         SetScreenHeight(cfg.ScreenLines);
  341.     SwitchCursor();
  342.     SendMessage(wnd, SHOW_WINDOW, 0, 0);
  343.     SendMessage(NULLWND, SHOW_MOUSE, 0, 0);
  344. }
  345.  
  346. static void CreateMenu(WINDOW wnd)
  347. {
  348.     AddAttribute(wnd, HASMENUBAR);
  349.     if (wnd->MenuBarWnd != NULLWND)
  350.         SendMessage(wnd->MenuBarWnd, CLOSE_WINDOW, 0, 0);
  351.     wnd->MenuBarWnd = CreateWindow(MENUBAR,
  352.                         NULL,
  353.                         GetClientLeft(wnd),
  354.                         GetClientTop(wnd)-1,
  355.                         1,
  356.                         ClientWidth(wnd),
  357.                         NULL,
  358.                         wnd,
  359.                         NULL,
  360.                         0);
  361.     SendMessage(wnd->MenuBarWnd, BUILDMENU, (PARAM) wnd->extension, 0);
  362. }
  363.  
  364. #ifdef INCLUDE_STATUSBAR
  365. static void CreateStatusBar(WINDOW wnd)
  366. {
  367.     if (wnd->StatusBar != NULLWND)    {
  368.         SendMessage(wnd->StatusBar, CLOSE_WINDOW, 0, 0);
  369.         wnd->StatusBar = NULLWND;
  370.     }
  371.     if (TestAttribute(wnd, HASBORDER) &&
  372.             TestAttribute(wnd, HASSTATUSBAR))    {
  373.         wnd->StatusBar = CreateWindow(STATUSBAR,
  374.                             NULL,
  375.                             GetClientLeft(wnd),
  376.                             GetBottom(wnd),
  377.                             1,
  378.                             ClientWidth(wnd),
  379.                             NULL,
  380.                             wnd,
  381.                             NULL,
  382.                             SAVESELF);
  383.     }
  384. }
  385. #endif
  386.  
  387. static char *Menus[9] = {
  388.     "~1.                      ",
  389.     "~2.                      ",
  390.     "~3.                      ",
  391.     "~4.                      ",
  392.     "~5.                      ",
  393.     "~6.                      ",
  394.     "~7.                      ",
  395.     "~8.                      ",
  396.     "~9.                      "
  397. };
  398.  
  399. #ifdef INCLUDE_MULTIDOCS
  400.  
  401. static int WindowSel;
  402.  
  403. static char *WindowName(WINDOW wnd)
  404. {
  405.     if (GetTitle(wnd) == NULL)    {
  406.         if (GetClass(wnd) == DIALOG)
  407.             return ((DBOX *)(wnd->extension))->HelpName;
  408.         else 
  409.             return "Untitled";
  410.     }
  411.     else
  412.         return GetTitle(wnd);
  413. }
  414.  
  415. static WINDOW oldFocus;
  416.  
  417. static void SetOldFocus(void)
  418. {
  419.     if (GetClass(inFocus) == MENUBAR)
  420.         oldFocus = PrevWindow(inFocus);
  421.     else
  422.         oldFocus = inFocus;
  423. }
  424.  
  425. void PrepFileMenu(void *wnd, struct Menu *mnu)
  426. {
  427.     DeactivateCommand(&MainMenu, ID_SAVE);
  428.     DeactivateCommand(&MainMenu, ID_SAVEAS);
  429.     DeactivateCommand(&MainMenu, ID_DELETEFILE);
  430.     DeactivateCommand(&MainMenu, ID_PRINT);
  431.     SetOldFocus();
  432.     if (oldFocus != NULLWND && GetClass(oldFocus) == EDITBOX) {
  433.         if (isMultiLine(oldFocus))    {
  434.             ActivateCommand(&MainMenu, ID_SAVE);
  435.             ActivateCommand(&MainMenu, ID_SAVEAS);
  436.             ActivateCommand(&MainMenu, ID_DELETEFILE);
  437.             ActivateCommand(&MainMenu, ID_PRINT);
  438.         }
  439.     }
  440. }
  441.  
  442. void PrepSearchMenu(void *wnd, struct Menu *mnu)
  443. {
  444.     DeactivateCommand(&MainMenu, ID_SEARCH);
  445.     DeactivateCommand(&MainMenu, ID_REPLACE);
  446.     DeactivateCommand(&MainMenu, ID_SEARCHNEXT);
  447.     SetOldFocus();
  448.     if (oldFocus != NULLWND && GetClass(oldFocus) == EDITBOX) {
  449.         if (isMultiLine(oldFocus))    {
  450.             ActivateCommand(&MainMenu, ID_SEARCH);
  451.             ActivateCommand(&MainMenu, ID_REPLACE);
  452.             ActivateCommand(&MainMenu, ID_SEARCHNEXT);
  453.         }
  454.     }
  455. }
  456.  
  457. void PrepEditMenu(void *wnd, struct Menu *mnu)
  458. {
  459.     DeactivateCommand(&MainMenu, ID_CUT);
  460.     DeactivateCommand(&MainMenu, ID_COPY);
  461.     DeactivateCommand(&MainMenu, ID_CLEAR);
  462.     DeactivateCommand(&MainMenu, ID_DELETETEXT);
  463.     DeactivateCommand(&MainMenu, ID_PARAGRAPH);
  464.     DeactivateCommand(&MainMenu, ID_PASTE);
  465.     DeactivateCommand(&MainMenu, ID_UNDO);
  466.     DeactivateCommand(&MainMenu, ID_SEARCH);
  467.     DeactivateCommand(&MainMenu, ID_SEARCHNEXT);
  468.     SetOldFocus();
  469.     if (oldFocus != NULLWND && GetClass(oldFocus) == EDITBOX) {
  470.         if (isMultiLine(oldFocus))    {
  471.             if (BlockMarked(oldFocus))    {
  472.                 ActivateCommand(&MainMenu, ID_CUT);
  473.                 ActivateCommand(&MainMenu, ID_COPY);
  474.                 ActivateCommand(&MainMenu, ID_CLEAR);
  475.                 ActivateCommand(&MainMenu, ID_DELETETEXT);
  476.             }
  477.             ActivateCommand(&MainMenu, ID_PARAGRAPH);
  478.             if (!TestAttribute(oldFocus, READONLY) &&
  479.                         Clipboard != NULL)
  480.                 ActivateCommand(&MainMenu, ID_PASTE);
  481.             if (oldFocus->DeletedText != NULL)
  482.                 ActivateCommand(&MainMenu, ID_UNDO);
  483.         }
  484.     }
  485. }
  486.  
  487. void PrepWindowMenu(void *wnd, struct Menu *mnu)
  488. {
  489.     struct PopDown *p0 = mnu->Selections;
  490.     struct PopDown *pd = mnu->Selections + 2;
  491.     struct PopDown *ca = mnu->Selections + 13;
  492.     int MenuNo = 0;
  493.     WINDOW wnd1 = Built.FirstWindow;
  494.     mnu->Selection = 0;
  495.     oldFocus = PrevWindow(inFocus);
  496.     while (wnd1 != NULLWND && MenuNo < 9)    {
  497.         if (GetClass(wnd1) != MENUBAR &&
  498.                 GetClass(wnd1) != STATUSBAR &&
  499.                     GetParent(wnd1) == wnd)    {
  500.             strncpy(Menus[MenuNo]+4, WindowName(wnd1), 20);
  501.             pd->SelectionTitle = Menus[MenuNo];
  502.             if (wnd1 == oldFocus)    {
  503.                 pd->Attrib |= CHECKED;
  504.                 mnu->Selection = MenuNo+2;
  505.             }
  506.             else
  507.                 pd->Attrib &= ~CHECKED;
  508.             pd++;
  509.             MenuNo++;
  510.         }
  511.         wnd1 = NextWindowBuilt(wnd1);
  512.     }
  513.     if (MenuNo)
  514.         p0->SelectionTitle = "~Close all";
  515.     else
  516.         p0->SelectionTitle = NULL;
  517.     if (wnd1 != NULLWND)    {
  518.         *pd++ = *ca;
  519.         if (mnu->Selection == 0)
  520.             mnu->Selection = 11;
  521.     }
  522.     pd->SelectionTitle = NULL;
  523. }
  524.  
  525. #ifdef INCLUDE_DIALOG_BOXES
  526. static int WindowPrep(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  527. {
  528.     switch (msg)    {
  529.         case INITIATE_DIALOG:    {
  530.             WINDOW wnd1 = Built.FirstWindow;
  531.             WINDOW cwnd = ControlWindow(&Windows, ID_WINDOWLIST);
  532.             int sel = 0;
  533.             if (cwnd == NULLWND)
  534.                 return FALSE;
  535.             while (wnd1 != NULLWND)    {
  536.                 if (GetClass(wnd1) != MENUBAR &&
  537.                         GetClass(wnd1) != STATUSBAR &&
  538.                             GetParent(wnd1) == GetParent(wnd) &&
  539.                                 wnd1 != wnd)    {
  540.                     if (wnd1 == oldFocus)
  541.                         WindowSel = sel;
  542.                     SendMessage(cwnd, ADDTEXT, (PARAM) WindowName(wnd1), 0);
  543.                     sel++;
  544.                 }
  545.                 wnd1 = NextWindowBuilt(wnd1);
  546.             }
  547.             SendMessage(cwnd, LB_SETSELECTION, WindowSel, 0);
  548. #ifdef INCLUDE_SCROLLBARS
  549.             AddAttribute(cwnd, VSCROLLBAR);
  550. #endif
  551.             PostMessage(cwnd, SHOW_WINDOW, 0, 0);
  552.             break;
  553.         }
  554.         case COMMAND:
  555.             switch ((int) p1)    {
  556.                 case ID_OK:
  557.                     WindowSel = SendMessage(ControlWindow(&Windows,
  558.                                         ID_WINDOWLIST),
  559.                                             LB_CURRENTSELECTION, 0, 0);
  560.                     break;
  561.                 case ID_WINDOWLIST:
  562.                     if ((int) p2 == LB_CHOOSE)
  563.                         SendMessage(wnd, COMMAND, ID_OK, 0);
  564.                     break;
  565.                 default:
  566.                     break;
  567.             }
  568.             break;
  569.         default:
  570.             break;
  571.     }
  572.     return DefaultWndProc(wnd, msg, p1, p2);
  573. }
  574. #endif
  575.  
  576. static void ChooseWindow(WINDOW wnd, int WindowNo)
  577. {
  578.     WINDOW wnd1 = GetFirstChild(wnd);
  579.     if (WindowNo == 9)    {
  580. #ifdef INCLUDE_DIALOG_BOXES
  581.         if (DialogBox(wnd, &Windows, TRUE, WindowPrep))
  582.             WindowNo = WindowSel;
  583.         else
  584. #endif
  585.             return;
  586.     }
  587.     while (wnd1 != NULLWND)    {
  588.         if (GetClass(wnd1) != MENUBAR && GetClass(wnd1) != STATUSBAR)
  589.             if (WindowNo-- == 0)
  590.                 break;
  591.         wnd1 = GetNextChild(wnd, wnd1);
  592.     }
  593.     SendMessage(wnd1, SETFOCUS, TRUE, 0);
  594.     if (wnd1->condition == ISMINIMIZED)
  595.         SendMessage(wnd1, RESTORE, 0, 0);
  596. }
  597.  
  598. #endif
  599.  
  600. static void DoWindowColors(WINDOW wnd)
  601. {
  602.     WINDOW cwnd;
  603.     InitWindowColors(wnd);
  604.     cwnd = GetFirstChild(wnd);
  605.     while (cwnd != NULLWND)    {
  606.         DoWindowColors(cwnd);
  607.         cwnd = GetNextChild(wnd, cwnd);
  608.     }
  609. }
  610.  
  611. static void SelectColors(WINDOW wnd)
  612. {
  613. #ifdef INCLUDE_DIALOG_BOXES
  614.     if (RadioButtonSetting(&Display, ID_MONO))
  615.         cfg.mono = 1;
  616.     else if (RadioButtonSetting(&Display, ID_REVERSE))
  617.         cfg.mono = 2;
  618.     else
  619.         cfg.mono = 0;
  620. #endif
  621.     if ((ismono() || video_mode == 2) && cfg.mono == 0)
  622.         cfg.mono = 1;
  623.  
  624.     if (cfg.mono == 1)
  625.         memcpy(cfg.clr, bw, sizeof bw);
  626.     else if (cfg.mono == 2)
  627.         memcpy(cfg.clr, reverse, sizeof reverse);
  628.     else
  629.         memcpy(cfg.clr, color, sizeof color);
  630.     DoWindowColors(wnd);
  631. }
  632.  
  633. #ifdef INCLUDE_DIALOG_BOXES
  634. static void SelectLines(WINDOW wnd)
  635. {
  636.     cfg.ScreenLines = 25;
  637.     if (isEGA() || isVGA())    {
  638.         if (RadioButtonSetting(&Display, ID_43LINES))
  639.             cfg.ScreenLines = 43;
  640.         else if (RadioButtonSetting(&Display, ID_50LINES))
  641.             cfg.ScreenLines = 50;
  642.     }
  643.     if (SCREENHEIGHT != cfg.ScreenLines)    {
  644.         int FullScreen = WindowHeight(wnd) == SCREENHEIGHT;
  645.         SetScreenHeight(cfg.ScreenLines);
  646.         if (FullScreen || SCREENHEIGHT-1 < GetBottom(wnd))
  647.             SendMessage(wnd, SIZE, (PARAM) GetRight(wnd),
  648.                 SCREENHEIGHT-1);
  649.     }
  650. }
  651. #endif
  652.  
  653. static void SetScreenHeight(int height)
  654. {
  655.     if (isEGA() || isVGA())    {
  656.         SendMessage(NULLWND, SAVE_CURSOR, 0, 0);
  657.         switch (height)    {
  658.             case 25:
  659.                 Set25();
  660.                 break;
  661.             case 43:
  662.                 Set43();
  663.                 break;
  664.             case 50:
  665.                 Set50();
  666.                 break;
  667.             default:
  668.                 break;
  669.         }
  670.         SendMessage(NULLWND, RESTORE_CURSOR, 0, 0);
  671.         SendMessage(NULLWND, RESET_MOUSE, 0, 0);
  672.         SendMessage(NULLWND, SHOW_MOUSE, 0, 0);
  673.     }
  674. }
  675.  
  676. #ifdef INCLUDE_MULTIDOCS
  677. static void SelectTexture(void)
  678. {
  679. #ifdef INCLUDE_DIALOG_BOXES
  680.     cfg.Texture = CheckBoxSetting(&Display, ID_TEXTURE);
  681. #endif
  682. }
  683.  
  684. static void SelectBorder(WINDOW wnd)
  685. {
  686. #ifdef INCLUDE_DIALOG_BOXES
  687.     cfg.Border = CheckBoxSetting(&Display, ID_BORDER);
  688. #endif
  689.     if (cfg.Border)
  690.         AddAttribute(wnd, HASBORDER);
  691.     else
  692.         ClearAttribute(wnd, HASBORDER);
  693. }
  694.  
  695. static void SelectStatusBar(WINDOW wnd)
  696. {
  697. #ifdef INCLUDE_DIALOG_BOXES
  698.     cfg.StatusBar = CheckBoxSetting(&Display, ID_STATUSBAR);
  699. #endif
  700.     if (cfg.StatusBar)
  701.         AddAttribute(wnd, HASSTATUSBAR);
  702.     else
  703.         ClearAttribute(wnd, HASSTATUSBAR);
  704. }
  705.  
  706. static void SelectTitle(WINDOW wnd)
  707. {
  708. #ifdef INCLUDE_DIALOG_BOXES
  709.     cfg.Title = CheckBoxSetting(&Display, ID_TITLE);
  710. #endif
  711.     if (cfg.Title)
  712.         AddAttribute(wnd, HASTITLEBAR);
  713.     else
  714.         ClearAttribute(wnd, HASTITLEBAR);
  715. }
  716. #endif
  717.  
  718. static void CloseAll(WINDOW wnd)
  719. {
  720.     WINDOW wnd1 = GetLastChild(wnd);
  721.     ClearAttribute(wnd, VISIBLE);
  722.     while (wnd1 != NULLWND)    {
  723.         if (GetClass(wnd1) == MENUBAR
  724. #ifdef INCLUDE_STATUSBAR
  725.                 || GetClass(wnd1) == STATUSBAR
  726. #endif
  727.                         )
  728.             wnd1 = GetPrevChild(wnd, wnd1);
  729.         else    {
  730.             SendMessage(wnd1, CLOSE_WINDOW, 0, 0);
  731.             wnd1 = GetLastChild(wnd);
  732.         }
  733.     }
  734.     AddAttribute(wnd, VISIBLE);
  735.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  736.     SendMessage(wnd, PAINT, 0, 0);
  737. }
  738.  
  739. static void FixTabMenu(void)
  740. {
  741.     char *cp = GetCommandText(&MainMenu, ID_TABS);
  742.     if (cp != NULL)    {
  743.         cp = strchr(cp, '(');
  744.         if (cp != NULL)    {
  745.             *(cp+1) = cfg.Tabs + '0';
  746.             if (GetClass(inFocus) == POPDOWNMENU)
  747.                 SendMessage(inFocus, PAINT, 0, 0);
  748.         }
  749.     }
  750. }
  751.  
  752.